package api

import (
	"github.com/gin-gonic/gin"
	jwt2 "github.com/golangblogs/gojwt"
	"goods/api/handler"
	"goods/consts"
)

func Goods(r *gin.Engine) {
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/create", handler.CreateUser) //用户注册
			user.POST("/login", handler.LoginUser)   //用户登录
		}
		goods := api.Group("/goods")
		{
			goods.Use(jwt2.JWTAuth(consts.JWT_SECRET_KEY))
			goods.POST("/token", handler.TokenGoods)   //商品中间件
			goods.POST("/create", handler.CreateGoods) //商品添加
			goods.POST("/query", handler.QueryGoods)   //商品查询
			goods.POST("/update", handler.UpdateGoods) //商品更新
			goods.POST("/delete", handler.DeleteGoods) //商品删除
		}
		evaluates := api.Group("/evaluates")
		{
			evaluates.Use(jwt2.JWTAuth(consts.JWT_SECRET_KEY))
			evaluates.POST("/token", handler.TokenEvaluates)   //评论中间件
			evaluates.POST("/create", handler.CreateEvaluates) //新增商品评论
			evaluates.POST("/query", handler.QueryEvaluates)   //查询评价
			evaluates.POST("/update", handler.UpdateEvaluates) //编辑评价
			evaluates.POST("/delete", handler.DeleteEvaluates) //删除评价
		}
		orders := api.Group("/orders")
		{
			orders.Use(jwt2.JWTAuth(consts.JWT_SECRET_KEY))
			orders.POST("/token", handler.TokenOrders)   //订单中间件
			orders.POST("/create", handler.CreateOrders) //创建订单
			orders.POST("/query", handler.QueryOrders)   //查询历史订单
			orders.POST("/update", handler.UpdateOrder)  //修改状态
			orders.POST("/delete", handler.DeleteOrder)  //撤销订单
		}
		token := api.Group("/token")
		{
			token.POST("/token", handler.TokenGet) //刷新token
		}
	}
}
